package com.bh.web.controller.vehicle;

import com.bh.common.annotation.Log;
import com.bh.common.core.controller.BaseController;
import com.bh.common.core.domain.AjaxResult;
import com.bh.common.core.page.TableDataInfo;
import com.bh.common.enums.BusinessType;
import com.bh.common.utils.poi.ExcelUtil;
import com.bh.vehicle.domain.JcDriver;
import com.bh.vehicle.service.IJcDriverService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 司机管理Controller
 * 
 * @author slx
 * @date 2023-11-26
 */
@RestController
@RequestMapping("/vehicle/driver")
public class JcDriverController extends BaseController
{
    @Autowired
    private IJcDriverService jcDriverService;

    /**
     * 查询司机管理列表
     */
    @ApiOperation("查询司机管理列表")
    @PreAuthorize("@ss.hasPermi('vehicle:driver:list')")
    @GetMapping("/list")
    public TableDataInfo list(JcDriver jcDriver)
    {
        startPage();
        List<JcDriver> list = jcDriverService.selectJcDriverList(jcDriver);
        return getDataTable(list);
    }

    /**
     * 查询车辆登记列表
     */
    @ApiOperation("查询车辆登记列表")
    @GetMapping("/searchList/{name}")
    public TableDataInfo searchList(@PathVariable String name)
    {
        JcDriver driver = new JcDriver();
        driver.setName(name);
        startPage();
        List<JcDriver> list = jcDriverService.selectJcDriverList(driver);
        return getDataTable(list);
    }


    /**
     * 查询司机管理列表
     */
    @ApiOperation("查询司机管理列表")
    @GetMapping("/allList")
    public AjaxResult allList(JcDriver jcDriver)
    {
        List<JcDriver> list = jcDriverService.selectJcDriverList(jcDriver);
        return AjaxResult.success(list);
    }

    /**
     * 导出司机管理列表
     */
    @PreAuthorize("@ss.hasPermi('vehicle:driver:export')")
    @Log(title = "司机管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JcDriver jcDriver)
    {
        List<JcDriver> list = jcDriverService.selectJcDriverList(jcDriver);
        ExcelUtil<JcDriver> util = new ExcelUtil<JcDriver>(JcDriver.class);
        util.exportExcel(response, list, "司机管理数据");
    }

    /**
     * 获取司机管理详细信息
     */
    @ApiOperation("获取司机管理详细信息")
    @PreAuthorize("@ss.hasPermi('vehicle:driver:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jcDriverService.selectJcDriverById(id));
    }

//    /**
//     * 新增司机管理
//     */
//    @ApiOperation("新增司机管理")
//    @PreAuthorize("@ss.hasPermi('vehicle:driver:add')")
//    @Log(title = "司机管理", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody JcDriver jcDriver)
//    {
//        return toAjax(jcDriverService.insertJcDriver(jcDriver));
//    }

    /**
     * 修改司机管理
     */
    @ApiOperation("修改司机管理")
    @PreAuthorize("@ss.hasPermi('vehicle:driver:edit')")
    @Log(title = "司机管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JcDriver jcDriver)
    {
        return toAjax(jcDriverService.saveOrUpdateJcDriver(jcDriver));
    }

    /**
     * 删除司机管理
     */
    @ApiOperation("删除司机管理")
    @PreAuthorize("@ss.hasPermi('vehicle:driver:remove')")
    @Log(title = "司机管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jcDriverService.deleteJcDriverByIds(ids));
    }
}
